package test3;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

//在文件内容的尾部追加内容
public class Write {
    public Write(String str, String file) {
        //1.创建源
        File f = new File(file);
        //2.选择流
        OutputStream o = null;
        try {
            o = new FileOutputStream(f, true);
        //3.操作
            byte[] b = str.getBytes();
            o.write(b, 0, str.length());
            o.flush();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                o.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

}

